<template>
  <!-- 详情开始 -->
  <a-modal
    :maskClosable="false"
    title="开票申请单单据详情"
    :width="1350"
    :bodyStyle="{
      padding: '0 24px'
    }"
    :visible="visible"
    @cancel="handleCancel"
    cancelText="关闭">
    <ErpFinanceInvoiceApplicationBillForm ref="realForm" :disabled="true" normal></ErpFinanceInvoiceApplicationBillForm>
    <template slot="footer">
      <a-button @click.stop="handleCancel">关闭</a-button>
    </template>
  </a-modal>
  <!-- 详情结束 -->
</template>

<script>

  import { filterObj } from '@/utils/util';
  import { getAction } from '@/api/manage'

  export default {
    name: 'ErpFinanceInvoiceBillPenetrate',
    components: {
      ErpFinanceInvoiceApplicationBillForm: ()=> import('@/views/erp/finance/invoice/modules/ErpFinanceInvoiceApplicationBillForm')
    },
    props: [],
    data() {
      return {
        visibleDetail: false,
        title: '还款金额明细',
        queryParam: {},
        toggleSearchStatus: false,
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'billNo',
          },
          {
            title:'申请公司',
            align:"center",
            dataIndex: 'applyCompany_dictText',
          },
          {
            title:'还款人',
            align:"center",
            dataIndex: 'proposer_dictText',
          },
          {
            title:'还款时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title:'本次累计还款金额（元）',
            align:"center",
            dataIndex: 'repaymentAmount',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:100,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          urlList: '/api/erp/finance/repayment/erpFinanceRepaymentSlip/list',
          queryById: '/api/erp/finance/invoice/erpFinanceInvoiceApplicationBill/queryById'
        },
        dataSource: [],
        loading: false,
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '50', '100', '200'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        isorter: {
          column: 'createTime',
          order: 'desc'
        },
        scrollTrigger: { x: true },
        visible: false,
        dictOptions: {},
        createTime: [],
        loanBillId: null
      }
    },
    created() {
      this.loadData();
      // 该方法触发屏幕自适应
      this.resetScreenSize();
      this.refresh();
      // 加载数据字典信息
      this.initDictConfig();
    },
    computed: {
    },
    methods: {
      initDictConfig() {
      },
      // 加载表单
      initData(id){
        getAction(this.url.queryById,{id:id}).then(res=>{
          if(!!res&&!!res.result){
            this.$refs.realForm.edit(res.result);
          }
        })
      },
      onDetail(record) {
        this.visible = false
        this.visibleDetail = true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        });
      },
      handleCancelDetail() {
        this.visible = true
        this.visibleDetail = false
      },
      handleToggleSearch() {
        this.toggleSearchStatus = !this.toggleSearchStatus;
      },
      createTimeChange(date, dateString) {
        this.$set(this.queryParam, 'createStartTime', dateString[0] + ' 00:00:00')
        this.$set(this.queryParam, 'createEndTime', dateString[1] + ' 23:59:59')
      },
      loadData(arg) {
        // 加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();// 查询条件
        if (!this.loanBillId) {
          this.dataSource = []
          this.ipagination.total = 0
          return
        } else {
          params.loanBillId = this.loanBillId;
        }
        getAction(this.url.urlList, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
            // 判断是否当前页没有数据且不为第一页
            if (this.dataSource.length == 0 && this.ipagination.current != 1) {
              this.ipagination.current = this.ipagination.current - 1
              this.loadData(this.ipagination.current - 1);
            } else {
              this.loading = false
            }

          }
        })
      },
      getQueryParams() {
        let param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param);
      },
      getQueryField() {
        let str = 'id,';
        for (let a = 0; a < this.columns.length; a++) {
          str += ',' + this.columns[a].dataIndex;
        }
        return str;
      },
      searchReset() {
        this.createTime = []
        let that = this;
        Object.keys(that.queryParam).forEach(function (key) {
          that.queryParam[key] = null;
        });
        that.loadData(1);
      },
      searchByquery() {
        this.loadData(1);
      },
      refresh() {
        this.loading = true
      },
      open(record) {
        this.loadData(1);
      },
      // 触发屏幕自适应
      resetScreenSize() {
        let screenWidth = document.body.clientWidth;
        if (screenWidth < 500) {
          this.scrollTrigger = { x: 800 };
        } else {
          this.scrollTrigger = {};
        }
      },
      handleCancel() {
        this.visible = false;
      },
      handleOk() {
        this.handleCancel();
      },
    }
  }
</script>
<style scoped>
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }

  .anty-img-wrap {
    height: 25px;
    position: relative;
  }

  .anty-img-wrap > img {
    max-height: 100%;
  }

</style>